# from selenium import webdriver
# from selenium.common.exceptions import SessionNotCreatedException
#
#
# def check_driver_compatibility():
#     try:
#         # 尝试启动浏览器
#         driver =webdriver.Chrome() #webdriver.Edge()
#         browser_version = driver.capabilities['browserVersion']
#         driver_version = driver.capabilities['chrome']['chromedriverVersion'].split(' ')[0]
#
#         print(f"浏览器版本: {browser_version}")
#         print(f"驱动版本: {driver_version}")
#
#         # 检查主版本是否一致
#         if browser_version.split('.')[0] == driver_version.split('.')[0]:
#             print("✅ 版本兼容")
#             return True
#         else:
#             print("❌ 版本不兼容")
#             return False
#
#     except SessionNotCreatedException as e:
#         if "This version of" in e.msg and "only supports" in e.msg:
#             print("⚠️ 检测到版本不兼容错误:")
#             print(e.msg)
#         else:
#             print("⚠️ 其他驱动错误:", e.msg)
#         return False
#     finally:
#         if 'driver' in locals():
#             driver.quit()
#
#
# # 执行检查
# if not check_driver_compatibility():
#     print("请下载匹配的WebDriver驱动")



from selenium import webdriver
from selenium.common.exceptions import SessionNotCreatedException

def test_driver_compatibility():
    try:
        driver = webdriver.Edge()
        print("✅ 驱动兼容性验证通过")
        print(f"浏览器版本: {driver.capabilities['browserVersion']}")
        print(f"驱动版本: {driver.capabilities['chrome']['chromedriverVersion'].split(' ')[0]}")
        driver.quit()
        return True
    except SessionNotCreatedException as e:
        if "This version of MSEdgeDriver" in e.msg:
            print("❌ 版本不兼容错误:")
            # 从错误信息中提取版本号
            msg_lines = e.msg.split('\n')
            print(f"驱动支持的版本: {msg_lines[0].split('version')[-1].strip()}")
            print(f"当前浏览器版本: {msg_lines[1].split('version is')[-1].split()[0]}")
        else:
            print("⚠️ 其他错误:", e.msg)
        return False